#include <bits/stdc++.h>

#define in read()
#define fi first
#define se second
#define pb push_back
#define rep(i, x, y) for(int i = (x); i <= (y); i++)
#define per(i, x, y) for(int i = (x); i >= (y); i--)

using namespace std;

typedef long long ll;
typedef double db;
typedef vector < int > vec;
typedef pair < int , int > pii;
typedef vector < pii > veg;

int read() {
    int x = 0; bool f = 0; char ch = getchar(); while(!isdigit(ch)) f |= ch == '-',ch = getchar();
    while(isdigit(ch)) x = x * 10 + (ch ^ 48),ch = getchar(); return f ? -x : x;
}

const int N = 2010;
const int TN = 2e5 + 10;
const int L = N * N;
const int dH[] = { 1, -1, 0, 0 };
const int dL[] = { 0, 0, 1, -1 };

int H,W,P,Q;
bool vis[N][N];
int ind[N][N];
int id[N][N],fa[L],tot,val[TN << 1],f[22][TN << 1],A[TN],B[TN],cnt,dis[N][N],dep[TN << 1];
char s[N][N];
vec G[TN << 1];

int gf(int x) { return fa[x] == x ? x : fa[x] = gf(fa[x]); }
void merge(int x,int y,int d) {
	x = gf(x); y = gf(y); if(x == y) return;
	++tot; fa[tot] = tot; G[tot].pb(x); G[tot].pb(y); val[tot] = d; fa[x] = fa[y] = tot;
}

void dfs(int x, int p) {
	f[0][x] = p; dep[x] = dep[p] + 1; rep(i, 1, 20) f[i][x] = f[i - 1][f[i - 1][x]];
	for(int y : G[x]) dfs(y, x);
}

int lca(int x,int y) {
	if(dep[x] < dep[y]) swap(x,y);
	per(i, 20, 0) if(dep[f[i][x]] >= dep[y]) x = f[i][x];
	if(x == y) return x;
	per(i, 20, 0) if(f[i][x] ^ f[i][y]) x = f[i][x],y = f[i][y];
	return f[0][x];
}

veg ed[L];

int main() {
#ifndef ONLINE_JUDGE
    freopen("1.in","r",stdin); freopen("output.txt","w",stdout);
#endif
	H = in,W = in,P = in,Q = in;
	rep(i, 1, H) scanf("%s",s[i] + 1);
	rep(i, 1, P) A[i] = in, B[i] = in, ind[A[i]][B[i]] = i,id[A[i]][B[i]] = ++cnt;
	queue < pii > q; rep(i, 1, P) vis[A[i]][B[i]] = true,q.push({ A[i], B[i] });
	rep(i, 1, cnt) fa[i] = i;
	tot = cnt;
	while(q.size()) {
		int x = q.front().fi, y = q.front().se; q.pop();
		rep(i, 0, 3) {
			int nx = x + dH[i],ny = y + dL[i];
			if(nx > 0 && ny > 0 && nx <= H && ny <= W){
				if(s[nx][ny] == '#') continue;
				if(!vis[nx][ny]) {
					vis[nx][ny] = true; dis[nx][ny] = dis[x][y] + 1; id[nx][ny] = id[x][y]; q.push({ nx, ny });
				}
				else {
					int tx = id[x][y],ty = id[nx][ny];
					if(tx == ty) continue;
					ed[dis[x][y] + dis[nx][ny]].pb({ tx, ty });
				}
			}
		}
	}
	rep(i, 0, N * N - 1) for(auto d : ed[i]) merge(d.fi, d.se, i);
	per(i, tot, 1) if(!f[0][i]) dfs(i, 0);
	rep(i, 1, Q) {
		int S = in,T = in;
		if(gf(S) ^ gf(T)) { puts("-1"); continue; }
		int L = lca(S,T); printf("%d\n",val[L]);
	} return 0;
}
